import { defineStore } from 'pinia';


interface User {
  userId: string;
  nickName: string;
  userName?: string;
  email?: string;
  ipaddr?: string;
}

export const userMainStore = defineStore('main', {
  persist: {
    enabled: true, //开启数据持久化
    strategies: [
      {
        key: 'singleLocalStorage', //给一个要保存的名称
        storage: localStorage, //sessionStorage / localStorage 存储方式
      },
    ],
  },
  state: () => {
    return {
      user: {} as User,
      menuTree: [
        {
          label: '首页',
          path: '/',
          meta: {
            icon: 'House',
          },
        },
        {
          label: '功能',
          path: '/',
          meta: {
            icon: 'Grid',
          },
          children: [
            {
              label: '证书申请',
              path: '/home',
              meta: {
                icon: 'Key',
              },
            },

          ],
        },
      ],
      // 侧边宽度
      asideWidth: '250px',
    };
  },
  getters: {
    getUserId: (state) => {
      return state.user.userId || '';
    },
  },
  actions: {
    setUserStore(user: any) {
      this.user = user;
    },
    setMenuTreeStore(menuTree: any) {
      this.menuTree = menuTree;
    },
    handleAsideWidth() {
      this.asideWidth = this.asideWidth == '250px' ? '64px' : '250px';
    },
  },
});
